package com.example.mybatislearn.common.page;

import org.springframework.data.domain.*;

import java.util.List;

public class PageHelper {

    //创建分页参数
    public static Pageable createPageable(int page, int size ) {
        return PageRequest.of(page,size);
    }

    //创建分页参数
    public static Pageable createPageable(int page, int size, Sort sort) {
        return PageRequest.of(page,size,sort);
    }

    public static Page createPage(List content, Pageable pageable, long total) {
        return new PageImpl(content,pageable,total);
    }

    public static Page doSelectPage(Pageable pageable,Select select) {
        com.github.pagehelper.Page page = com.github.pagehelper.PageHelper.startPage(pageable.getPageNumber(), pageable.getPageSize()).doSelectPage(() -> select.doSelect());
        return createPage(page,pageable,page.getTotal());
    }


}
